home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / makeReferenceObject.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  3.4 KB  |  101 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. global proc makeReferenceObject()
  18. //
  19. // Description
  20. //        Looks at the selection list for the first piece of
  21. //        geometry and then proceeeds to:
  22. //                duplicate it
  23. //                translate it slightly
  24. //                template it
  25. //                make it a reference object of the original
  26. //                surface.
  27. //
  28. {
  29.     // Get the relevant selected objects (transforms or geometryShapes)
  30.     string $selectedObjects[] = `ls -sl -type transform -type geometryShape`;
  31.  
  32.     if (size($selectedObjects) >= 1) {
  33.  
  34.         // Get the geometryShapeNodes for the first selected object.
  35.  
  36.         string $allShapeNodes[] = 
  37.             `ls -sl -dagObjects -type geometryShape $selectedObjects[0]`;
  38.         string $originalShapeNodes[];
  39.  
  40.         int $i = 0;
  41.         for ($shape in $allShapeNodes) {
  42.             int $intermediate = `getAttr ($shape + ".intermediateObject")`;
  43.  
  44.             if (!$intermediate) {
  45.                 $originalShapeNodes[$i] = $shape;
  46.                 $i++;
  47.             }
  48.         }
  49.         
  50.         if (size($originalShapeNodes) >= 1) {
  51.             // There is at least one geometryShape node so proceed
  52.  
  53.             // Duplicate the object we are working on
  54.             string $duplicatedObj[] = 
  55.                 `duplicate -n ($selectedObjects[0] + "_reference") $selectedObjects[0]`;
  56.  
  57.             // Move the object slightly and template it.
  58.             // (commenting out the move to fix bug 115663
  59.             //move -r 5 0 0 $duplicatedObj[0];
  60.             setAttr ($duplicatedObj[0] + ".template") true;
  61.             string $listOfParents[] = `listRelatives -p $duplicatedObj[0]`;
  62.             if (size($listOfParents) > 0) {
  63.                 parent -w $duplicatedObj[0];
  64.             }
  65.  
  66.             // Get a list of geometryShape nodes for the duplicated object
  67.             string $duplicatedShapeNodesTmp[] = 
  68.                 `ls -sl -dagObjects -type geometryShape $duplicatedObj[0]`;
  69.             // This list will have the duplicated objects.  Cull them.
  70.             string $duplicatedShapeNodes[];
  71.             int $i=0;
  72.             for ($shape in $duplicatedShapeNodesTmp) {
  73.                 int $intermediate = `getAttr ($shape + ".intermediateObject")`;
  74.                 if (!$intermediate) {
  75.                     $duplicatedShapeNodes[$i] = $shape;
  76.                     $i++;
  77.                 }
  78.             }
  79.             
  80.             // The originalShapeNodes and duplicatedShapeNodes are arrays
  81.             // that must have the same elements or we are in big trouble
  82.             
  83.             if (size($originalShapeNodes) == size($duplicatedShapeNodes)) {
  84.  
  85.                 int $i = 0;
  86.                 for ($shapeNode in $originalShapeNodes) {
  87.  
  88.                     connectAttr ($duplicatedShapeNodes[$i] + ".msg") 
  89.                         ($shapeNode + ".referenceObject");
  90.  
  91.                     rename $duplicatedShapeNodes[$i] ($shapeNode + "_reference");
  92.  
  93.                     $i++;
  94.                 }
  95.             } else {
  96.                 warning ("Reference object has different topology than original surface. Do each shape individually.");                
  97.             }
  98.         }
  99.     }
  100. }
  101.